package com.example.main.fragment.home

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.example.lib_base.mvvm.BaseFragment
import com.example.main.R
import com.example.main.databinding.FragmentHomeLayoutBinding

import com.example.main.databinding.FragmentMessageBinding
import com.example.main.fragment.home.adapter.HomeNavItemAdapter
import com.example.main.fragment.home.adapter.HomeNotionAdapter
import com.example.main.fragment.home.bean.HomeNavItem
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeLayoutBinding, HomeViewModel>() {

    val honmNavItemList = mutableListOf<HomeNavItem>()
    lateinit var homeNavITemAdapter: HomeNavItemAdapter
    lateinit var homeNotionAdapter: HomeNotionAdapter
    init {
        honmNavItemList.add(HomeNavItem(R.drawable.img_17, "车位管理"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_10, "访客登记"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_11, "物业报修"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_12, "考勤打卡"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_13, "房源信息"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_14, "商家推荐"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_15, "月卡会员"))
        honmNavItemList.add(HomeNavItem(R.drawable.img_16, "设备管理"))
    }
    override fun initView() {
        vm.getHomeNotion(0, 10)
        homeNotionAdapter = HomeNotionAdapter()
        biding.homeRecNotice.layoutManager = LinearLayoutManager(requireContext())
        biding.homeRecNotice.adapter = homeNotionAdapter

        homeNavITemAdapter = HomeNavItemAdapter()
        homeNavITemAdapter.setNewData(honmNavItemList)
        biding.homeRecBar.layoutManager = GridLayoutManager(requireContext(), 4)
        biding.homeRecBar.adapter = homeNavITemAdapter
        homeNavITemAdapter.setOnItemClickListener { _, _, position ->
            // 处理点击事件
            when (position) {
                0 -> {
                    // 车位管理
                    ARouter.getInstance().build("/cartmanage/CheweiActivity").navigation()
                }

                1 -> {
                    // 访客登记
                }

                2 -> {
                    // 物业报修
                }

                3 -> {
                    ARouter.getInstance().build("/exam/ExamActivity").navigation()
                    // 考勤打卡
                }

                4 -> {
                    // 房源信息
                }

                5 -> {
                    // 商家推荐
                }

                6 -> {
                    // 月卡会员
                }

                7 -> {
                    // 设备管理
                }
            }
        }
    }

    override fun initData() {
        vm.homeNotionSuccess.observe(this) {
            homeNotionAdapter.setNewData( it)
            homeNotionAdapter.notifyDataSetChanged()
        }

    }


}